import { getLocalHistories } from "@/utils/storage"

//定义初始化函数
const initState = {
  list: [] as string[],
  searchHistory: getLocalHistories()
}
export type SearchType =
  { type: 'search/suggestion', payload: string[] } |
  { type: 'search/history', payload: string[] }

export default function SearchReducer(state = initState, action: SearchType) {
  switch (action.type) {
    case 'search/suggestion':
      return { ...state, list: action.payload }
    case 'search/history':
      return { ...state, searchHistory: action.payload }
    default:
      return state
  }
}